package com.android.webrtcsdkdev

import android.graphics.Bitmap
import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import com.vc.videosdk.Constant
import com.vc.videosdk.VcOperateManager
import com.vc.videosdk.custom.OperatorListener
import com.vc.videosdk.custom.PreviewOperatorListener
import com.vc.videosdk.xlog.XLogUtil

class MainActivity : AppCompatActivity() {
    var iv_picture: ImageView? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        iv_picture = findViewById(R.id.iv_picture)

        findViewById<Button>(R.id.bt_start_app).setOnClickListener {
            VcOperateManager.getInstance().startApp(
                "1223",
                Constant.WEB_SOCKET_IP,
                Constant.WEB_SOCKET_TEST_TOKEN,
                "com.minhui.networkcapture",
                object : OperatorListener {
                    override fun operatorResult(instanceId: String, code: Int, message: String) {
                        XLogUtil.d("startApp result code:$code,,,message:$message")
                    }
                })
        }

        findViewById<Button>(R.id.bt_stop_app).setOnClickListener {
            VcOperateManager.getInstance().stopApp(
                "1223",
                Constant.WEB_SOCKET_IP,
                Constant.WEB_SOCKET_TEST_TOKEN,
                "com.minhui.networkcapture",
                object : OperatorListener {
                    override fun operatorResult(instanceId: String, code: Int, message: String) {
                        XLogUtil.d("stopApp result code:$code,,,message:$message")
                    }
                })
        }

        findViewById<Button>(R.id.bt_uninstall_app).setOnClickListener {
            VcOperateManager.getInstance().unInstallApp(
                "1223",
                Constant.WEB_SOCKET_IP,
                Constant.WEB_SOCKET_TEST_TOKEN,
                "com.minhui.networkcapture",
                object : OperatorListener {
                    override fun operatorResult(instanceId: String, code: Int, message: String) {
                        XLogUtil.d("unInstallApp result code:$code,,,message:$message")
                    }
                })
        }

        findViewById<Button>(R.id.bt_hide_app).setOnClickListener {
            VcOperateManager.getInstance().hideApp(
                "1223",
                Constant.WEB_SOCKET_IP,
                Constant.WEB_SOCKET_TEST_TOKEN,
                object : OperatorListener {
                    override fun operatorResult(instanceId: String, code: Int, message: String) {
                        XLogUtil.d("hideApp result code:$code,,,message:$message")
                    }
                })
        }

        findViewById<Button>(R.id.bt_display_app).setOnClickListener {
            VcOperateManager.getInstance().displayApp(
                "1223",
                Constant.WEB_SOCKET_IP,
                Constant.WEB_SOCKET_TEST_TOKEN,
                object : OperatorListener {
                    override fun operatorResult(instanceId: String, code: Int, message: String) {
                        XLogUtil.d("displayApp result code:$code,,,message:$message")
                    }
                })
        }


        findViewById<Button>(R.id.bt_root_app).setOnClickListener {
            var packageList: MutableList<String> =
                mutableListOf<String>("com.minhui.networkcapture", "ru.andr7e.deviceinfohw")

            VcOperateManager.getInstance().rootApp(
                "1223",
                Constant.WEB_SOCKET_IP,
                Constant.WEB_SOCKET_TEST_TOKEN,
                1,
                packageList,
                object : OperatorListener {
                    override fun operatorResult(instanceId: String, code: Int, message: String) {
                        XLogUtil.d("displayApp result code:$code,,,message:$message")
                    }
                })
        }

        findViewById<Button>(R.id.bt_root_sys).setOnClickListener {
            VcOperateManager.getInstance().systemRoot(
                "1223",
                Constant.WEB_SOCKET_IP,
                Constant.WEB_SOCKET_TEST_TOKEN,
                1,
                object : OperatorListener {
                    override fun operatorResult(instanceId: String, code: Int, message: String) {
                        XLogUtil.d("systemApp result code:$code,,,message:$message")
                    }
                })
        }

        findViewById<Button>(R.id.bt_virtual_location).setOnClickListener {
            VcOperateManager.getInstance().virtualLocation(
                "1223",
                Constant.WEB_SOCKET_IP,
                Constant.WEB_SOCKET_TEST_TOKEN,
                "114.064524",
                "22.549054",
                object : OperatorListener {
                    override fun operatorResult(instanceId: String, code: Int, message: String) {
                        XLogUtil.d("virtualLocation result code:$code,,,message:$message")
                    }
                })
        }

        findViewById<Button>(R.id.bt_sys_preview_start).setOnClickListener {
            VcOperateManager.getInstance().sysPreviewStart(
                "1223",
                Constant.WEB_SOCKET_IP,
                Constant.WEB_SOCKET_TEST_TOKEN,
                "1",
                "640",
                "480",
                "90",
                object : PreviewOperatorListener {
                    override fun operatorResult(
                        instanceId: String,
                        code: Int,
                        type: String,
                        message: String
                    ) {
                        XLogUtil.d("sysPreviewStart result code:$code,,,message:$message")
                    }

                    override fun previewData(bitmap: Bitmap) {
                        XLogUtil.d("返回的预览图数据 previewData bitmap:$bitmap")
                        runOnUiThread {
                            iv_picture?.setImageBitmap(bitmap)
                        }
                    }
                })
        }

        findViewById<Button>(R.id.bt_sys_preview_stop).setOnClickListener {
            VcOperateManager.getInstance().sysPreviewStop(
                "1223",
                Constant.WEB_SOCKET_IP,
                Constant.WEB_SOCKET_TEST_TOKEN,
                object : OperatorListener {
                    override fun operatorResult(instanceId: String, code: Int, message: String) {
                        XLogUtil.d("sysPreviewStop result code:$code,,,message:$message")
                    }
                })
        }



        findViewById<Button>(R.id.bt_sys_clipboard).setOnClickListener {
            VcOperateManager.getInstance().clipBoard(
                "1223",
                Constant.WEB_SOCKET_IP,
                Constant.WEB_SOCKET_TEST_TOKEN,
                "粘贴的内容",
                object : OperatorListener {
                    override fun operatorResult(instanceId: String, code: Int, message: String) {
                        XLogUtil.d("clipBoard result code:$code,,,message:$message")
                    }
                })
        }


    }
}